<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pages extends CI_Controller {
    var $datah;
        public function __construct()
	{
                // parent::Controller();
		parent::__construct();
                $this->load->model('menu_model');
                $this->load->helper('url');
                $this->datah['baseurl'] = base_url();
                session_start();
	}

	public function view($page = 'home')
	{
            if ( ! file_exists('application/views/pages/'.$page.'.php'))
            {
		// Whoops, we don't have a page for that!
		show_404();
            }
            
          //  $this->load->library('session');
               $this->datah['showmenu'] = TRUE;
                        
            // Check if session started - are we logged in
            // if not set the role to public
            $role = 'public';   // predefine the var 
            if (isset($_SESSION)) {
             if ( isset($_SESSION['logged_in'])) {
                $role = $_SESSION['role']; } else { $role = 'public'; } } 
            
            $this->datah['role'] = $role;    
            
            // get the appropriate menu structure
            $menu = $this->menu_model->getmenu( $role ,$page );
            $ids['menu'] = $menu;
            $this->datah['menu'] = $menu;
            $ids['base'] = base_url();
            
            $data['title'] = ucfirst($page); // Capitalize the first letter
	    $this->load->view('templates/header', $this->datah);
         //   $this->load->view('menus/mainmenu', $ids);
            
            if ($page == 'home' || $page == 'about' || $page == 'contact' || $page == 'adrates') {
                $this->load->view('templates/sidebar');
                $this->load->view('pages/'.$page, $data);
                $this->load->view('templates/footer', $data);
            } else {
                $this->load->view('pages/'.$page, $data);
            }
            
          //  $this->load->view('templates/footer', $data);
	}
        
        /*
    * Test page
    */
   public function testpage() {
       $this->datah['showmenu'] = TRUE;
       $role = 'public';   // predefine the var 
            if (isset($_SESSION)) {
             if ( isset($_SESSION['logged_in'])) {
                $role = $_SESSION['role']; } else { $role = 'public'; } } 
            
            $this->datah['role'] = $role;    
            
            // get the appropriate menu structure
            $menu = $this->menu_model->getmenu( $role , 'home' );
            $ids['menu'] = $menu;
            $this->datah['menu'] = $menu;
            
            
            
       $this->load->view('templates/header', $this->datah);
       $this->load->view('testview');
       $this->load->view('templates/footer');
   }
      
       
}
?>
